<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php $this->load->view('common/head'); ?>
<style>
    .nav-user-photo {
        line-height: 40px;
        height: 40px;
        border: 1px solid #E1E1E1;
        border-radius: 100%;
    }
</style>

<?php $this->load->view('common/header'); ?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar'); ?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs'); ?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set'); ?>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <form class="form-inline" action="" method="get">
                            <label class="inline">用户工种</label>
                            <select id="group" name="group" class="multiselect select2">
                                <option value="">可选择</option>
                                <?php if (isset($service)) { ?>
                                    <?php foreach ($service as $key => $val) { ?>
                                        <option value="<?php echo $val['id']; ?>"
                                                <?php if (isset($search['group']) && $search['group'] == $val['id']){ ?>selected="selected"<?php } ?> ><?php echo $val['name']; ?></option>
                                    <?php } ?>
                                <?php } ?>
                            </select>
                            <select name="user_dress" id="user_dress" class="select2" size="1">
                                <option value="0">请选择服务城市</option>
                                <?php if (isset($city) && !empty($city)) { ?>
                                    <?php foreach ($city as $key => $val) { ?>
                                        <option value="<?php echo $val['area_id']; ?>"
                                                <?php if (isset($search['user_dress']) && $search['user_dress'] == $val['area_id']){ ?>selected="selected"<?php } ?> ><?php echo $val['area_name']; ?></option>
                                    <?php } ?>
                                <?php } ?>
                            </select>
                            <input type="text" name="user_name" value="<?php if(isset($search['user_name'])){echo $search['user_name'];}?>" placeholder="用户名" class="form-control">
                            <button type="submit" class="btn btn-purple btn-sm">
                                <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
                                查询
                            </button>
                            <button type="button" class="btn btn-purple btn-sm" id="export">
                                <span class="ace-icon fa fa-plus icon-on-right bigger-110"></span>
                                导出
                            </button>
                        </form>
                    </div>
                    <div class="col-xs-12" style="margin-top: 20px;">
                        <table class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th>头像</th>
                                <th>用户名</th>
                                <th>用户组</th>
                                <th>服务区域</th>
                                <th>电话</th>
                                <th>紧急电话</th>
                                <th>积分</th>
                                <th>查看上传资料</th>
                                <th class="center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (isset($users)) {
                                foreach ($users as $key => $val) { ?>
                                    <tr>
                                        <td class="center">
                                            <?php if (!empty($val['user_avatar'])) { ?>
                                                <img class="nav-user-photo" src="<?php echo base_url($val['user_avatar']); ?>"
                                                     alt="头像">
                                            <?php }else{ ?>
                                                <img class="nav-user-photo" src="<?php echo base_url('uploads/avatar/default/avatar_middle.jpg'); ?>"
                                                     alt="头像">
                                            <?php } ?>
                                        </td>
                                        <td><?php echo $val['user_name']; ?></td>
                                        <td class="grouptd">
                                            <span class="group"
                                                  val="<?php echo $val['user_id']; ?>" <?php if ($val['user_group'] == 3) {
                                                echo 'style="color:red"';
                                            } ?>><?php echo $val['title']; ?></span>
                                        </td>
                                        <td><?php echo $val['user_dress_name']; ?></td>
                                        <td><?php echo $val['user_tel']; ?></td>
                                        <td><?php echo $val['user_urgent_tel']; ?></td>
                                        <!--                                    <td>-->
                                        <?php //if($val['user_guide_number']==1){echo '是';}else{echo '否';} ?><!--</td>-->
                                        <!--                                    <td>-->
                                        <?php //if($val['is_association_member']==1){echo '是';}else{echo '否';} ?><!--</td>-->
                                        <td>
                                            <?php echo $val['user_credit']; ?>
                                            <a href="javascript:;"
                                               val="<?php echo site_url(X_URL . 'Drivers/edit_credit'); ?>"
                                               user_id="<?php echo $val['user_id'] ?>"
                                               credit="<?php echo $val['user_credit']; ?>" class="edit_credit">
                                                <i class="ace-icon fa fa-pencil bigger-100"></i>修改积分
                                            </a>
                                        </td>
                                        <td>
                                            <a class="blue" href="<?php echo site_url(X_URL . 'Drivers/material/'.$val['user_id']); ?>">
                                                <i class="ace-icon fa fa-search-plus bigger-130"></i>查看上传资料
                                                <?php if($val['new_material'] == 1){?>
                                                    <span style="color: red">*</span>
                                                <?php }?>
                                            </a>
                                        </td>
                                        <td class="center">
                                            <a href="<?php echo site_url(X_URL . 'drivers/detail/' . $val['user_id']); ?>">会员详细</a>&nbsp;
                                            <a href="<?php echo site_url(X_URL . 'drivers/edit/' . $val['user_id']); ?>">修改</a>&nbsp;
                                            <a class="del" href="javascript:;"
                                               val="<?php echo site_url(X_URL . 'drivers/del'); ?>"
                                               user="<?php echo $val['user_id']; ?>"
                                               name="<?php echo $val['user_name']; ?>" title="删除">删除</a>
                                        </td>
                                    </tr>
                                <?php }
                            } ?>
                            </tbody>
                        </table>
                        <?php if ($pagination) { ?>
                            <ul class="pagination"><?php echo $pagination; ?></ul><?php } ?>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div><!-- /.main-content -->

        </div><?php $this->load->view('common/footer'); ?>
    

    <?php $this->load->view('common/footerjs'); ?>
    <!-- inline scripts related to this page -->
    <script type="text/javascript">

        $(function () {
            $("#officialnews ul").html('<div class="ace-icon fa fa-spinner fa-spin orange"></div>');
        })
        $("#adduser").click(function () {
            window.location.href = "add";
        });
        $(".del").click(function () {
            var url = $(this).attr('val');
            var user_name = $(this).attr('name');
            var user_id = $(this).attr('user');
            layer.confirm('您确定要删除 ' + user_name + ' 么？', {
                btn: ['删除', '取消'] //按钮
            }, function () {
                $.ajax({
                    type: "post",
                    url: url,
                    data: {'user_id': user_id, 'csrf_test_name': ci_csrf_token()},
                    dataType: "JSON",
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg(msg.info, {
                                time: 1000, //1s后自动关闭
                                shade: 0.1,
                                icon: 1
                            }, function () {
                                window.location.reload();
                            });
                        } else {
                            layer.msg(msg.info, {
                                time: 1000, //1s后自动关闭
                                shade: 0.1
                            });
                            return false;
                        }
                    }
                })
            }, function () {
            });
        });
        //prompt层
        $(".edit_credit").click(function () {
            var user_id = $(this).attr("user_id");
            var url = $(this).attr("val");
            var credit = $(this).attr("credit");
            layer.prompt({title: '修改会员积分', value: credit}, function (value, index) {
                $.ajax({
                    type: "post",
                    url: url,
                    data: {'user_id': user_id, 'user_credit': value, 'csrf_test_name': ci_csrf_token()},
                    dataType: "JSON",
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.close(index);
                            layer.msg(msg.info, {
                                time: 1000, //1s后自动关闭
                                shade: 0.1
                            }, function () {
                                window.location.href = window.location.href;
                            });
                        } else {
                            layer.msg(msg.msg);
                            return false;
                        }
                    }
                })
            });
        });
        $("#export").click(function () {
            var group = $("#group").val();
            var user_dress = $("#user_dress").val();
            var url = baseurl+"index.php/manage/Drivers/export_excel";
            window.location.href=url+"?group="+group+"&user_dress="+user_dress;
        });
    </script>
</body>
</html>
